**Variable coding dofile**
**Counterterrorism Cooperation Scale calculation, and altnerates**

**filling in missing data as 0s**
 mvencode  chostintl csignintl cintlcoop ncnosign ncboycott ncnoncomply ncquestionsign ncsponsor ncsponsorsusp nsusactsponsor cctacts carrests incantresolve ncnoacts ncdownplay cinstchange clegal cimmigration cborders nclegal inlegal inborders inimmigration ncborders ncimmigration sitterrorsource sitterrorwatch sitterrorgroup sithaven situsatttacks situsthreats cusarrest cusagreement cuscoop cintelshare cextradition cfinancing cmessaging ncintelshare ncextradition ncfinancing ncmessaging cparticipateus csupportus callowus coverflight cmiluspressure chostus ncopposeus ncprotestactions, mv(0)

**coding higher-level variables**

gen C_IntlForum = 0

replace C_IntlForum = 1 if  chostintl == 1 |  csignintl == 1 |  cintlcoop == 1

gen NC_IntlForum = 0

replace NC_IntlForum = 1 if  ncnosign == 1 |  ncboycott == 1 |  ncquestionsign == 1

gen NC_Noncomply = ncnoncomply

gen NC_PotentialSponsor = 0

replace NC_PotentialSponsor  = 1 if ncsponsorsusp == 1 &  ncsponsor == 0

replace  NC_PotentialSponsor = 1 if nsusactsponsor == 1 & ncsponsor == 0

gen C_CTacts = 0

replace C_CTacts = 1 if  cctacts == 1 |  carrests == 1

gen NC_CTacts = 0

replace NC_CTacts = 1 if  incantresolve == 1 |  ncnoacts == 1

gen NC_downplay =  ncdownplay

gen NC_sponsor = ncsponsor

gen C_Legalchange =  clegal

gen C_BordersandImmigration = 0

replace C_BordersandImmigration = 1 if  cimmigration == 1 |  cborders == 1

gen C_Institchange = 0

replace C_Institchange = 1 if cinstchange == 1

replace C_Institchange = 1 if cinstchange == 1

replace C_Institchange = 0 if C_Legalchange == 1 | C_BordersandImmigration == 1

 gen NC_Legalchange = 0

replace NC_Legalchange = 1 if  nclegal == 1 |  inlegal == 1

gen NC_BordersandImmigration = 0

replace NC_BordersandImmigration = 1 if  inborders == 1 |  inimmigration == 1 |  ncborders == 1 |  ncimmigration == 1

gen C_USarrest = cusarrest

gen C_USagreement = cusagreement

gen C_Intelshare = cintelshare

gen C_Extradition = cextradition

gen C_Financing = cfinancing

gen C_Messaging = cmessaging

gen C_UScoop = cuscoop

replace C_UScoop = 0 if C_USarrest == 1 | C_USagreement == 1 | C_Intelshare == 1 | C_Extradition == 1 | C_Financing == 1 | C_Messaging == 1

gen NC_Intelshare = ncintelshare

gen NC_Extradition = ncextradition

gen NC_Financing = ncfinancing

gen NC_Messaging = ncmessaging

gen C_ParticipateUS = cparticipateus

gen C_AllowUS = callowus

gen C_Overflight = callowus

gen C_MilUSpressure = cmiluspressure

gen C_HostUS = chostus

gen C_SupportUS = csupportus

replace C_SupportUS = 0 if C_ParticipateUS == 1 | C_AllowUS == 1 | C_Overflight == 1 | C_MilUSpressure == 1 | C_HostUS == 1

gen NC_OpposeUS = ncopposeus

gen NC_Protestactions = ncprotestactions

egen count = rowtotal( C_IntlForum NC_IntlForum NC_Noncomply NC_PotentialSponsor C_CTacts NC_CTacts NC_downplay NC_s
> ponsor C_Legalchange C_BordersandImmigration C_Institchange NC_Legalchange NC_BordersandImmigration C_USarrest C_USa
> greement C_Intelshare C_Extradition C_Financing C_Messaging C_UScoop NC_Intelshare NC_Extradition NC_Financing NC_Me
> ssaging C_ParticipateUS C_AllowUS C_Overflight C_MilUSpressure C_HostUS C_SupportUS NC_OpposeUS NC_Protestactions)

egen Ccount = rowtotal( C_IntlForum C_CTacts C_Legalchange C_BordersandImmigration C_Institchange C_USarrest C_USagreement C_Intelshare C_Extradition C_Financing C_Messaging C_UScoop C_ParticipateUS C_AllowUS C_Overflight C_MilUSpressure C_HostUS C_SupportUS)

egen NCcount = rowtotal(NC_IntlForum NC_Noncomply NC_PotentialSponsor NC_CTacts NC_downplay NC_sponsor NC_Legalchange NC_BordersandImmigration NC_Intelshare NC_Extradition NC_Financing NC_Messaging NC_OpposeUS NC_Protestactions)

gen C10 = Ccount/1.8

. gen NC10 = NCcount/1.4

. gen Coopcount = Ccount-NCcount

. gen Coopcount10 = C10-NC10


. gen Coopcount10 = C10-NC10

gen percentcoop = Ccount/count
gen percentnoncoop = NCcount/count

gen percentcoopdiff = percentcoop - percentnoncoop


gen IN_Instit = 0
replace IN_Instit = 1 if  inborders == 1 | inlegal == 1 | inimmigration == 1

gen IN_CTacts = 0
replace IN_CTacts = 1 if  incantresolve == 1

**controls**
gen RussChinally = 0
replace RussChinally = 1 if ccode == 373 | ccode == 630 | ccode == 640 | ccode == 700 | ccode == 701 | ccode == 702 | ccode == 703 | ccode == 704 | ccode == 705 | ccode == 710

**indexes**
**count difference**
egen Ccount = rowtotal( C_IntlForum C_CTacts C_Legalchange C_BordersandImmigration C_Institchange C_USarrest C_USagreement C_Intelshare C_Extradition C_Financing C_Messaging C_UScoop C_ParticipateUS C_AllowUS C_Overflight C_MilUSpressure C_HostUS C_SupportUS)

egen NCcount = rowtotal(NC_IntlForum NC_Noncomply NC_PotentialSponsor NC_CTacts NC_downplay NC_sponsor NC_Legalchange NC_BordersandImmigration NC_Intelshare NC_Extradition NC_Financing NC_Messaging NC_OpposeUS NC_Protestactions)

gen C10 = Ccount/1.8

gen NC10 = NCcount/1.4

gen Coopcount10 = C10-NC10

**percentage**
egen Ccount = rowtotal( C_IntlForum C_CTacts C_Legalchange C_BordersandImmigration C_Institchange C_USarrest C_USagreement C_Intelshare C_Extradition C_Financing C_Messaging C_UScoop C_ParticipateUS C_AllowUS C_Overflight C_MilUSpressure C_HostUS C_SupportUS)

egen NCcount = rowtotal(NC_IntlForum NC_Noncomply NC_PotentialSponsor NC_CTacts NC_downplay NC_sponsor NC_Legalchange NC_BordersandImmigration NC_Intelshare NC_Extradition NC_Financing NC_Messaging NC_OpposeUS NC_Protestactions)

gen percentcoop = Ccount/count
gen percentnoncoop = NCcount/count
gen percentcoopdiff = percentcoop - percentnoncoop

**adjusted indexes**
egen count_v2 = rowtotal(c_ctacts c_legalchange c_bordersandimmigration c_institchange c_usarrest c_intelshare c_extradition c_financing c_messaging c_participateus c_allowus c_overflight c_hostus nc_noncomply nc_potentialsponsor nc_ctacts nc_downplay nc_legalchange nc_extradition nc_financing nc_messaging)
egen Ccount_v2 = rowtotal(c_ctacts c_legalchange c_bordersandimmigration c_institchange c_usarrest c_intelshare c_extradition c_financing c_messaging c_participateus c_allowus c_overflight c_hostus)
egen NCcount_v2 = rowtotal(nc_noncomply nc_potentialsponsor nc_ctacts nc_downplay nc_legalchange nc_extradition nc_financing nc_messaging)
gen C10_v2 = Ccount_v2/1.3
gen NC10_v2 = NCcount_v2/0.8
gen Coopcount10_v2 = C10_v2-NC10_v2
gen Coopcount_v2 = CCount_v2 - NCcount_v2

gen percentcoop_v2 = Ccount_v2/count_v2
gen percentnoncoop_v2 = NCcount_v2/count_v2
gen percentcoopdiff_v2 = percentcoop_v2 - percentnoncoop_v2


**sub-indexes v21**
**by type of cooperation**
*terrorism sponsorship**
gen terrorsponsorwv2 = 0

**international cooperation**
gen intlcoopwv2 = 0
replace intlcoopwv2 = -1 if nc_noncomply == 1

**domestic terrorist actions**
gen terroractswv2 = terroractsw

**institutional reform**
 egen institcountv2 = rowtotal( c_legalchange c_bordersandimmigration c_institchange nc_legalchange)
 egen Cinstitcountv2 = rowtotal(c_legalchange c_bordersandimmigration c_institchange)
 egen NCinstitcountv2 = rowtotal (nc_legalchange)
 gen Cinstitpercentv2 = Cinstitcount/institcount
 gen NCinstitpercentv2 = NCinstitcount/institcount
 gen institcountpercentv2 = Cinstitpercent-NCinstitpercent
 replace institcountwv2 = 0 if institcountwv2 == .
 **compliance with US domestic initiatives**
 gen domcomplwv2 = domcomplw
   
  **US military actions**
egen USmilcountv2 = rowtotal(c_participateus c_allowus c_overflight c_hostus c_intelshare)
gen USmilwv2 = USmilcountv2/5
replace USmilwv2 = 0 if USmilwv3 == .

**logit versions of intlcoop and terrorsponsor for robustness checks**
gen terrorsponsorwv3 = terrorsponsorwv2 + 1
gen intlcoopwv3 = intlcoopwv2 + 1

**sub-indexes**
**by type of cooperation**
*terrorism sponsorship**
gen terrorsponsor = .
replace terrorsponsor = -1 if nc_potentialsponsor == 1 | nc_sponsor == 1
replace terrorsponsor = 1 if nc_potentialsponsor == 0 & nc_sponsor == 0
replace terrorsponsor = 0 if nc_potentialsponsor == . & nc_sponsor == .
**international cooperation**
egen intlcoopcount = rowtotal(nc_intlforum nc_noncomply c_intlforum)
egen Cintlcoop = rowtotal (c_intlforum)
egen NCintlcoop = rowtotal(nc_intlforum nc_noncomply)
gen Cintlpercent = Cintlcoop/intlcoopcount
gen NCintlpercent = NCintlcoop/intlcoopcount
gen intlcooppercent = Cintlpercent-NCintlpercent
**domestic terrorist actions**
gen terroracts = .
replace terroracts = -1 if nc_ctacts == 1 & c_ctacts == 0
replace terroracts = 1 if c_ctacts == 1 & nc_ctacts == 0
replace terroracts = 0 if nc_ctacts == 1 & c_ctacts == 1 
replace terroracts = . if nc_ctacts == 0 & c_ctacts == 0
replace terroracts = 0 if nc_ctacts == . | c_ctacts == .
**institutional reform**
 egen institcount = rowtotal( c_legalchange c_bordersandimmigration c_institchange nc_legalchange nc_bordersandimmigration)
 egen Cinstitcount = rowtotal(c_legalchange c_bordersandimmigration c_institchange)
 egen NCinstitcount = rowtotal (nc_legalchange nc_bordersandimmigration)
 gen Cinstitpercent = Cinstitcount/institcount
 gen NCinstitpercent = NCinstitcount/institcount
 gen institcountpercent = Cinstitpercent-NCinstitpercent
 **compliance with US domestic initiatives**
 egen domcompliancecount = rowtotal( nc_downplay c_usarrest c_extradition c_financing c_messaging nc_financing nc_messaging  nc_extradition)
 egen Cdomcompliancecount = rowtotal(c_usarrest c_extradition c_financing c_messaging)
 egen NCdomcompliancecount = rowtotal(nc_downplay nc_financing nc_messaging  nc_extradition)
 gen Cdomcompliancepercent = Cdomcompliancecount/domcompliancecount
 gen NCdomcompliancepercent = NCdomcompliancecount/domcompliancecount
 gen domcompliancepercent = Cdomcompliancepercent-NCdomcompliancepercent
 **compliance with US international initiatives** 
 egen intlcomplcount = rowtotal( c_miluspressure c_usagreement c_intelshare c_uscoop nc_intelshare)
 egen Cintlcomplcount = rowtotal(c_usagreement c_intelshare c_uscoop c_miluspressure)
 egen NCintlcomplcount = rowtotal(nc_intelshare)
 gen Cintlcomplpercent = Cintlcomplcount/intlcomplcount
 gen NCintlcomplpercent = NCintlcomplcount/intlcomplcount
 gen intlcomplpercent = Cintlcomplpercent-NCintlcomplpercent
  **US military actions**
egen USmilcount = rowtotal(c_participateus c_allowus c_overflight c_hostus c_supportus nc_opposeus nc_protestactions)
egen CUSmilcount = rowtotal(c_participateus c_allowus c_overflight c_hostus c_supportus)
egen NCUSmilcount = rowtotal(nc_opposeus nc_protestactions)
gen CUSmilpercent = CUSmilcount/USmilcount
gen NCUSmilpercent = NCUSmilcount/USmilcount
gen USmilpercent = CUSmilpercent-NCUSmilpercent


**factor analysis**
polychoric c_ctacts c_legalchange c_bordersandimmigration c_institchange c_usarrest c_intelshare c_extradition c_financing  c_hostus
matrix R = r(R)
factormat R, n(627) forcepsd factors(2)
rotate, varimax
predict polycoop1 polycoop2

polychoric nc_downplay nc_legalchange nc_extradition nc_financing nc_messaging
matrix R = r(R)
factormat R, n(627) forcepsd factors(1)
rotate, varimax
predict polynoncoop1 polynoncoop2

gen factorcoopdiff = polycoop1 - polynoncoop1
**alpha tests**

**reshape command**

reshape wide relstate count ccount nccount c10 nc10 coopcount coopcount10 percentcoop percentnoncoop percentcoopdiff count_v2 Ccount_v2 NCcount_v2 C10_v2 NC10_v2 Coopcount10_v2 percentcoop_v2 percentnoncoop_v2 percentcoopdiff_v2, i(cname) j(year)

**in wide**
egen meancoopcount10_96to00 = rowmean( coopcount101996 coopcount101997 coopcount101998 coopcount101999 coopcount102000)

egen meancoopcount10_01to04 = rowmean(coopcount102001 coopcount102002 coopcount102003 coopcount102004)

egen meancoopcount10_05on = rowmean(coopcount102005 coopcount102006 coopcount102007 coopcount102008 coopcount102009)

egen meancooppercent_96to00 = rowmean( percentcoopdiff1996 percentcoopdiff1997 percentcoopdiff1998 percentcoopdiff1999 percentcoopdiff2000)

egen meancooppercent_01to04 = rowmean(percentcoopdiff2001 percentcoopdiff2002 percentcoopdiff2003 percentcoopdiff2004)

egen meancoopercent_05on = rowmean (percentcoopdiff2005 percentcoopdiff2006 percentcoopdiff2007 percentcoopdiff2008 percentcoopdiff2009)

**with adjusted indexes**
egen meancount_v296to00 = rowmean(Coopcount10_v21996 Coopcount10_v21997 Coopcount10_v21998 Coopcount10_v21999 Coopcount10_v22000)

egen meancount_v201to04 = rowmean(Coopcount10_v22001 Coopcount10_v22002 Coopcount10_v22003 Coopcount10_v22004)

egen meancount_v205on = rowmean(Coopcount10_v22005 Coopcount10_v22006 Coopcount10_v22007 Coopcount10_v22008 Coopcount10_v22009)

egen meanpercent_v296to00 = rowmean(percentcoopdiff_v21996 percentcoopdiff_v21997 percentcoopdiff_v21998 percentcoopdiff_v21999 percentcoopdiff_v22000)

egen meanpercent_v201to04 = rowmean(percentcoopdiff_v22001 percentcoopdiff_v22002 percentcoopdiff_v22003 percentcoopdiff_v22004)

egen meanpercent_v205on = rowmean(percentcoopdiff_v22005 percentcoopdiff_v22006 percentcoopdiff_v22007 percentcoopdiff_v22008 percentcoopdiff_v22009)

**poscoop**
gen poscoop = .
replace poscoop = 0 if percentcoopdiff_vtwo < 0.00000000000000000001
replace poscoop = 1 if percentcoopdiff_vtwo > 0

**C10s**
gen Cten = Ccount/1.8
gen NCten = NCcount/1.4
gen Coopcountten = Cten-NCten
gen Cten_vtwo = Ccount_vtwo/1.3
gen NCten_vtwo = NCcount_vtwo/0.8

gen Coopcountten_vtwo = Cten_vtwo-NCten_vtwo


**new versions of percentcoopdiff with missings as 0s**
gen percentcoopdiff_wmissing = percentcoopdiff
(243 missing values generated)

. replace percentcoopdiff_wmissing = 0 if percentcoopdiff == .
(243 real changes made)

. replace percentcoopdiff_wmissing = . if year==2010
(49 real changes made, 49 to missing)

 gen percentcoopdiff_v2_wmissing = percentcoopdiff_vtwo
(303 missing values generated)

. replace percentcoopdiff_v2_wmissing = 0 if percentcoopdiff_vtwo == .
(303 real changes made)

. replace percentcoopdiff_v2_wmissing = . if year == 2010
(49 real changes made, 49 to missing)

**cooplevel**
gen cooplevel = .

replace cooplevel = 1 if percentcoopdiff_vtwo < 0

replace cooplevel = 0 if percentnoncoop_vtwo == 1

replace cooplevel = 3 if percentcoopdiff_vtwo == 0

replace cooplevel = 4 if percentcoopdiff_vtwo > 0

replace cooplevel = 5 if percentcoop_vtwo == 1

replace cooplevel = 2 if percentcoopdiff_vtwo == .

gen cooplevel_threelevel = 0
replace cooplevel_threelevel = 1 if cooplevel > 1
replace cooplevel_threelevel = 2 if cooplevel > 3


**Religion-State calculations**

gen smallWC = .
replace smallWC = 1 if W_mod_ < 2
replace smallWC = 0 if W_mod_ > 1
replace smallWC = . if W_mod_ == .

gen smallWCconstant = .
replace smallWCconstant = 1 if medianWC < 2
replace smallWCconstant = 0 if medianWC > 1
replace smallWCconstant = . if medianWC == .
replace smallWCconstant = 1 if medianWC == .
replace smallWCconstant = 1 if W_mod == .


**recoding WC**
replace smallWC = 0 if country == "Bosnia"
replace smallWCconstant = 0 if country == "Bosnia"
replace smallWC = 0 if country == "Lebanon"
replace smallWCconstant = 0 if country == "Lebanon"
replace smallWC = 0 if country == "Somalia"
replace smallWCconstant = 0 if country == "Somalia"

replace smallWC = 0 if country == "Afghanistan" 
replace smallWCconstant = 0 if country == "Afghanistan"

replace smallWC = 0 if country == "Iraq" & year > 2002
replace smallWCconstant = 0 if country == "Iraq" & year > 2002
replace smallWC = 0 if country == "Bosnia-Herzegovina"
replace smallWCconstant = 0 if country == "Bosnia-Herzegovina"
replace smallWC = 1 if country == "Brunei"
replace smallWCconstant = 1 if country == "Brunei"
replace smallWC = 1 if country == "Maldives"
replace smallWCconstant = 1 if country == "Maldives"

**finishing coding relstateties**
replace official_Islamic = 0 if country == "Libya"
replace political_ties = 1 if country == "Iraq" & year > 2002
replace official_Islamic = 1 if country == "Iraq" & year > 2002
replace political_ties = 1 if country == "Nigeria"
replace political_ties = 1 if country == "Comoros"
think about Mauritania

make have no political ties-
replace political_ties = 0 if country == "Burkina Faso" | country == "Chad" | country == "Djibouti" | country == "Gambia" | country == "Guinea" | country == "Niger" | country == "Sierra Leone"


**relstateties**
gen relstatevarying = .
replace relstatevarying = 0 if official_Islamic == 0 & political_ties == 0 & smallWC_ == 1
replace relstatevarying = 1 if official_Islamic == 0 & political_ties == 1 & smallWC_ == 0
replace relstatevarying = 1 if official_Islamic == 0 & political_ties == 0 & smallWC_ == 0
replace relstatevarying = 1 if official_Islamic == 0 & political_ties == 1 & smallWC_ == 1
replace relstatevarying = 2 if official_Islamic == 1 & political_ties == 0 & smallWC_ == 1
replace relstatevarying = 3 if official_Islamic == 1 & political_ties == 1 & smallWC_ == 1
replace relstatevarying = 4 if official_Islamic == 1 & political_ties == 1 & smallWC_ == 0

gen relstate = .
replace relstate = 0 if official_Islamic == 0 & political_ties == 0 & smallWCconstant == 1
replace relstate = 1 if official_Islamic == 0 & political_ties == 1 & smallWCconstant == 0
replace relstate = 1 if official_Islamic == 0 & political_ties == 0 & smallWCconstant == 0
replace relstate = 1 if official_Islamic == 0 & political_ties == 1 & smallWCconstant == 1
replace relstate = 2 if official_Islamic == 1 & political_ties == 0 & smallWCconstant == 1
replace relstate = 3 if official_Islamic == 1 & political_ties == 1 & smallWCconstant == 1
replace relstate = 4 if official_Islamic == 1 & political_ties == 1 & smallWCconstant == 0

gen relstate5yrvary = .
replace relstate5yrvary = 0 if official_Islamic == 0 & political_ties == 0 &  minsmallWC == 1
replace relstate5yrvary = 1 if official_Islamic == 0 & political_ties == 1 &  minsmallWC == 0
replace relstate5yrvary = 1 if official_Islamic == 0 & political_ties == 0 &  minsmallWC == 0
replace relstate5yrvary = 1 if official_Islamic == 0 & political_ties == 1 &  minsmallWC == 1
replace relstate5yrvary = 2 if official_Islamic == 1 & political_ties == 0 &  minsmallWC == 1
replace relstate5yrvary = 3 if official_Islamic == 1 & political_ties == 1 &  minsmallWC == 1
replace relstate5yrvary = 4 if official_Islamic == 1 & political_ties == 1 &  minsmallWC == 0

gen relstatenowc = .
replace relstatenowc = 0 if official_Islamic == 0 & political_ties == 0 
replace relstatenowc = 1 if official_Islamic == 0 & political_ties == 1 
replace relstatenowc = 2 if official_Islamic == 1 & political_ties == 0 
replace relstatenowc = 3 if official_Islamic == 1 & political_ties == 1 

**controls**


*dip exchange- did maximum DR,recoded 9s into 0s. Used 1995 value for 1996-1999, 2000 value for 2000-2004, 2005 value for 2005-2010

**usmid - MID with US since 1990, or war using list that goes to 2007**
**intra-state- Somalia, Pakistan**

**terrorism**
gen terrorattacknodeaths1995 = 0
replace terrorattacknodeaths1995 = 1 if terrorismdeaths1995 == -1
gen terrorattacknodeaths1996 = 0
replace terrorattacknodeaths1996 = 1 if terrorismdeaths1996 == -1
gen terrorattacknodeaths1997 = 0
replace terrorattacknodeaths1997 = 1 if terrorismdeaths1997 == -1
gen terrorattacknodeaths1998 = 0
replace terrorattacknodeaths1998 = 1 if terrorismdeaths1998 == -1
gen terrorattacknodeaths1999 = 0
replace terrorattacknodeaths1999 = 1 if terrorismdeaths1999 == -1
gen terrorattacknodeaths2000 = 0
replace terrorattacknodeaths2000 = 1 if terrorismdeaths2000 == -1
gen terrorattacknodeaths2001 = 0
replace terrorattacknodeaths2001 = 1 if terrorismdeaths2001 == -1
gen terrorattacknodeaths2002 = 0
replace terrorattacknodeaths2002 = 1 if terrorismdeaths2002 == -1
gen terrorattacknodeaths2003 = 0
replace terrorattacknodeaths2003 = 1 if terrorismdeaths2003 == -1
gen terrorattacknodeaths2004 = 0
replace terrorattacknodeaths2004 = 1 if terrorismdeaths2004 == -1
gen terrorattacknodeaths2005 = 0
replace terrorattacknodeaths2005 = 1 if terrorismdeaths2005 == -1
gen terrorattacknodeaths2006 = 0
replace terrorattacknodeaths2006 = 1 if terrorismdeaths2006 == -1
gen terrorattacknodeaths2007 = 0
replace terrorattacknodeaths2007 = 1 if terrorismdeaths2007 == -1
gen terrorattacknodeaths2008 = 0
replace terrorattacknodeaths2008 = 1 if terrorismdeaths2008 == -1
gen terrorattacknodeaths2009 = 0
replace terrorattacknodeaths2009 = 1 if terrorismdeaths2009 == -1
gen terrorattacknodeaths2010 = 0
replace terrorattacknodeaths2010 = 1 if terrorismdeaths2010 == -1

replace terrorismdeaths1995 = 0 if terrorismdeaths1995 == -1 | terrorismdeaths1995 == .
replace terrorismdeaths1996 = 0 if terrorismdeaths1996 == -1 | terrorismdeaths1996 == .
replace terrorismdeaths1997 = 0 if terrorismdeaths1997 == -1 | terrorismdeaths1997 == .
replace terrorismdeaths1998 = 0 if terrorismdeaths1998 == -1 | terrorismdeaths1998 == .
replace terrorismdeaths1999 = 0 if terrorismdeaths1999 == -1 | terrorismdeaths1999 == .
replace terrorismdeaths2000 = 0 if terrorismdeaths2000 == -1 | terrorismdeaths2000 == .
replace terrorismdeaths2001 = 0 if terrorismdeaths2001 == -1 | terrorismdeaths2001 == .
replace terrorismdeaths2002 = 0 if terrorismdeaths2002 == -1 | terrorismdeaths2002 == .
replace terrorismdeaths2003 = 0 if terrorismdeaths2003 == -1 | terrorismdeaths2003 == .
replace terrorismdeaths2004 = 0 if terrorismdeaths2004 == -1 | terrorismdeaths2004 == .
replace terrorismdeaths2005 = 0 if terrorismdeaths2005 == -1 | terrorismdeaths2005 == .
replace terrorismdeaths2006 = 0 if terrorismdeaths2006 == -1 | terrorismdeaths2006 == .
replace terrorismdeaths2007 = 0 if terrorismdeaths2007 == -1 | terrorismdeaths2007 == .
replace terrorismdeaths2008 = 0 if terrorismdeaths2008 == -1 | terrorismdeaths2008 == .
replace terrorismdeaths2009 = 0 if terrorismdeaths2009 == -1 | terrorismdeaths2009 == .
replace terrorismdeaths2010 = 0 if terrorismdeaths2010 == -1 | terrorismdeaths2010 == .

gen terrortwoyear1996 = (terrorismdeaths1995 + terrorismdeaths1996)/2
gen terrortwoyear1997 = (terrorismdeaths1996 + terrorismdeaths1997)/2
gen terrortwoyear1998 = (terrorismdeaths1997 + terrorismdeaths1998)/2
gen terrortwoyear1999 = (terrorismdeaths1998 + terrorismdeaths1999)/2
gen terrortwoyear2000 = (terrorismdeaths1999 + terrorismdeaths2000)/2
gen terrortwoyear2001 = (terrorismdeaths2000 + terrorismdeaths2001)/2
gen terrortwoyear2002 = (terrorismdeaths2001 + terrorismdeaths2002)/2
gen terrortwoyear2003 = (terrorismdeaths2002 + terrorismdeaths2003)/2
gen terrortwoyear2004 = (terrorismdeaths2003 + terrorismdeaths2004)/2
gen terrortwoyear2005 = (terrorismdeaths2004 + terrorismdeaths2005)/2
gen terrortwoyear2006 = (terrorismdeaths2005 + terrorismdeaths2006)/2
gen terrortwoyear2007 = (terrorismdeaths2006 + terrorismdeaths2007)/2
gen terrortwoyear2008 = (terrorismdeaths2008 + terrorismdeaths2007)/2
gen terrortwoyear2009 = (terrorismdeaths2008 + terrorismdeaths2009)/2
gen terrortwoyear2010 = (terrorismdeaths2009 + terrorismdeaths2010)/2



**conflictintensity**
replace intensity1995 = 0 if intensity1995 == .
replace intensity1996 = 0 if intensity1996 == .
replace intensity1997 = 0 if intensity1997 == .
replace intensity1998 = 0 if intensity1998 == .
replace intensity1999 = 0 if intensity1999 == .
replace intensity2000 = 0 if intensity2000 == .
replace intensity2001 = 0 if intensity2001 == .
replace intensity2002 = 0 if intensity2002 == .
replace intensity2003 = 0 if intensity2003 == .
replace intensity2004 = 0 if intensity2004 == .
replace intensity2005 = 0 if intensity2005 == .
replace intensity2006 = 0 if intensity2006 == .
replace intensity2007 = 0 if intensity2007 == .
replace intensity2008 = 0 if intensity2008 == .
replace intensity2009 = 0 if intensity2009 == .
replace intensity2010 = 0 if intensity2010 == .

**DD**
gen regime2009 = regime2008
gen regime2010 = regime2008
gen democracy2009 = democracy2008
gen democracy2010 = democracy2008

**power**
gen cinc2008 = cinc2007
gen cinc2009 = cinc2007
gen cinc2010 = cinc2007

**affinity**
gen s3un4608i2009 = s3un4608i2008
gen s3un4608i2010 = s3un4608i2008
gen s2un4608i2009 = s2un4608i2008
gen s2un4608i2010 = s2un4608i2008

**trade**
gen trade2010 = trade2009


**in long**
**terrorismlevel**
gen terrorismlevel = 0
replace terrorismlevel = 1 if terrorattacknodeaths == 1
replace terrorismlevel = 2 if terrorismdeaths > 0
replace terrorismlevel = 3 if terrorismdeaths > 9
replace terrorismlevel = 4 if terrorismdeaths > 50


**aid**
gen usaid = econaid+milaid

**means and rolling averages**


**averages**

egen meancount_vtwo_1 = rowmean(Coopcountten_vtwo1996 Coopcountten_vtwo1997 Coopcountten_vtwo1998 Coopcountten_vtwo1999 Coopcountten_two2000)

egen meancount_vtwo_2 = rowmean(Coopcountten_vtwo2001 Coopcountten_vtwo2002 Coopcountten_vtwo2003 Coopcountten_vtwo2004)

egen meancount_vtwo_3 = rowmean(Coopcountten_vtwo2005 Coopcountten_vtwo2006 Coopcountten_vtwo2007 Coopcountten_vtwo2008 Coopcountten_vtwo2009)

egen meanpercent_vtwo_1 = rowmean(percentcoopdiff_vtwo1996 percentcoopdiff_vtwo1997 percentcoopdiff_vtwo1998 percentcoopdiff_vtwo1999 percentcoopdiff_vtwo2000)

egen meanpercent_vtwo_2 = rowmean(percentcoopdiff_vtwo2001 percentcoopdiff_vtwo2002 percentcoopdiff_vtwo2003 percentcoopdiff_vtwo2004)

egen meanpercent_vtwo_3 = rowmean(percentcoopdiff_vtwo2005 percentcoopdiff_vtwo2006 percentcoopdiff_vtwo2007 percentcoopdiff_vtwo2008 percentcoopdiff_vtwo2009)

egen meanpercent_vtwowmissing_1 = rowmean(percentcoopdiff_v2_wmissing1996 percentcoopdiff_v2_wmissing1997 percentcoopdiff_v2_wmissing1998 percentcoopdiff_v2_wmissing1999 percentcoopdiff_v2_wmissing2000)

egen meanpercent_vtwowmissing_2 = rowmean(percentcoopdiff_v2_wmissing2001 percentcoopdiff_v2_wmissing2002 percentcoopdiff_v2_wmissing2003 percentcoopdiff_v2_wmissing2004)

egen meanpercent_vtwowmissing_3 = rowmean(percentcoopdiff_v2_wmissing2005 percentcoopdiff_v2_wmissing2006 percentcoopdiff_v2_wmissing2007 percentcoopdiff_v2_wmissing2008 percentcoopdiff_v2_wmissing2009)

**control means**
gen relstate_1 = relstate_1996
gen relstate_2 = relstate_2001
gen relstate_3 = relstate_2005
gen relgroup_1 = rowmax(relgroup1996 relgroup1997 relgroup1998 relgroup1999 relgroup2000)
gen relgroup_2 = rowmax(relgroup2001 relgroup2002 relgroup2003 relgroup2004)
gen relgroup_3 = rowmax(relgroup2005 relgroup2006 relgroup2007 relgroup2008 relgroup2009 relgroup2010)
gen alliance = alliance1996
gen usmid = usmid1996
gen muslim = muslim1996
egen polity_1 = rowmax(polity1996 polity1997 polity1998 polity1999 polity2000)
egen polity_2 = rowmax(polity2001 polity2002 polity2003 polity2004)
egen polity_3 = rowmax(polity2005 polity2006 polity2007 polity2008 polity2009 polity2010)
gen politytwo = politytwo1996
gen dr_1 = maxdr1996
gen dr_2 = maxdr2000 
gen dr_3 = maxdr2005
egen intensity_1 = rowmax(intensity1996 intensity1997 intensity1998 intensity1999 intensity2000)
egen intensity_2 = rowmax(intensity2001 intensity2002 intensity2003 intensity2004)
egen intensity_3 = rowmax(intensity2005 intensity2006 intensity2007 intensity2008 intensity2009 intensity2010)
egen affinity_1 = rowmax(s3un4608i1996 s3un4608i1997 s3un4608i1998 s3un4608i1999 s3un4608i2000)
egen affinity_2 = rowmax(s3un4608i2001 s3un4608i2002 s3un4608i2003 s3un4608i2004)
egen affinity_3 = rowmax(s3un4608i2005 s3un4608i2006 s3un4608i2007 s3un4608i2008)
egen trade_1 = rowmean(trade1996 trade1997 trade1998 trade1999 trade2000)
egen trade_2 = rowmean(trade2001 trade2003 trade 2002 trade2004)
egen trade_3 = rowmean(trade2005 trade2006 trade2007 trade2008 trade2009)
egen democracy_1 = rowmax(democracy1996 democracy1997 democracy1998 democracy1999 democracy2000)
egen democracy_2 = rowmax(democracy2001 democracy2002 democracy2003 democracy2004)
egen democracy_3 = rowmax(democracy2005 democracy2006 democracy2007 democracy2008)
egen regime_1 = rowmax(regime1996 regime1997 regime1998 regime1999 regime2000)
egen regime_2 = rowmax(regime2001 regime2002 regime2003 regime2004)
egen regime_3 = rowmax(regime2005 regime2006 regime2007 regime2008)
egen terrorism_1 = rowmax(terrorismlevel1996 terrorismlevel1997 terrorismlevel1998 terrorismlevel1999 terrorismlevel2000)
egen terrorism_2 = rowmax(terrorismlevel2001 terrorismlevel2002 terrorismlevel2003 terrorismlevel2004)
egen terrorism_3 = rowmax(terrorismlevel2005 terrorismlevel2006 terrorismlevel2007 terrorismlevel2008 terrorismlevel2009 terrorismlevel2010)
egen usaid_1 = rowmean(usaid1996 usaid1997 usaid1998 usaid1999 usaid2000)
egen_usaid_2 = rowmean(usaid2001 usaid2002 usaid2003 usaid2004)
egen usaid_3 = rowmean(usaid2005 usaid2006 usaid2007 usaid2008 usaid2009 usaid2010)
egen cinc_1 = rowmean(cinc1996 cinc1997 cinc1998 cinc1999 cinc2000)
egen cinc_2 = rowmean(cinc2001 cinc2003 cinc2002 cinc2004)
egen cinc_3 = rowmean(cinc2005 cinc2006 cinc2007)

**reshaping back**

reshape long meancount_vtwo_ meanpercent_vtwo_ meanpercent_vtwowmissing_ polity_ dr_ intensity_ affinity_ trade_ democracy_ regime_ terrorism_ usaid_ cinc_ relstate_ relgroup_, i(ccode) j(timeperiod)

**rolling averages**
**reshape from CT dataset**
**rolling averages for each year are the average of that year with the previous year (e.g. 2008 is 2007-2008). There is no value for 1996. Controls are for the year alone.**
egen coopdiffrolling1997 = rowmean(percentcoopdiff_v2_wmissing1996 percentcoopdiff_v2_wmissing1997)
egen coopdiffrolling1998 = rowmean(percentcoopdiff_v2_wmissing1998 percentcoopdiff_v2_wmissing1997)
egen coopdiffrolling1999 = rowmean(percentcoopdiff_v2_wmissing1998 percentcoopdiff_v2_wmissing1999)
egen coopdiffrolling2000 = rowmean(percentcoopdiff_v2_wmissing1999 percentcoopdiff_v2_wmissing2000)
egen coopdiffrolling2001 = rowmean(percentcoopdiff_v2_wmissing2001 percentcoopdiff_v2_wmissing2000)
egen coopdiffrolling2002 = rowmean(percentcoopdiff_v2_wmissing2001 percentcoopdiff_v2_wmissing2002)
egen coopdiffrolling2003 = rowmean(percentcoopdiff_v2_wmissing2002 percentcoopdiff_v2_wmissing2003)
egen coopdiffrolling2004 = rowmean(percentcoopdiff_v2_wmissing2003 percentcoopdiff_v2_wmissing2004)
egen coopdiffrolling2005 = rowmean(percentcoopdiff_v2_wmissing2004 percentcoopdiff_v2_wmissing2005)
egen coopdiffrolling2006 = rowmean(percentcoopdiff_v2_wmissing2006 percentcoopdiff_v2_wmissing2005)
egen coopdiffrolling2007 = rowmean(percentcoopdiff_v2_wmissing2006 percentcoopdiff_v2_wmissing2007)
egen coopdiffrolling2008 = rowmean(percentcoopdiff_v2_wmissing2008 percentcoopdiff_v2_wmissing2007)
egen coopdiffrolling2009 = rowmean(percentcoopdiff_v2_wmissing2008 percentcoopdiff_v2_wmissing2009)
egen coopdiffrolling2010 = rowmean(percentcoopdiff_v2_wmissing2010 percentcoopdiff_v2_wmissing2009)

**regions**
gen region = 0
replace region = 1 if ccode > 399
replace region = 2 if ccode > 599
replace region = 3 if ccode > 699

**ccodeyear**
egen ccodeyear = concat(ccode year)
destring ccodeyear, replace

**relstate4level**
gen relstate3level = 0
replace relstate3level = 1 if relstate5yrvary == 1
replace relstate3level = 2 if relstate5yrvary == 2 | relstate5yrvary == 3
replace relstate3level = 3 if relstate5yrvary == 4

**subscales w missing**
 
 
gen USmilwmissing =  USmilpercent_
replace USmilwmissing = 0 if  USmilpercent_ == .
gen intlcoopwmissing = intlcooppercent_ 
replace intlcoopwmissing = 0 if intlcooppercent_  == .
gen intlcomplwmissing = intlcomplpercent_
replace intlcomplwmissing = 0 if intlcomplpercent_ == .
gen terroractswmissing = terroracts_
replace terroractswmissing = 0 if terroracts_ == .
gen terrorsponsorwmissing = terrorsponsor_
replace terrorsponsorwmissing = 0 if terrorsponsor_ == .
gen institwmissing =  institcountpercent_ 
replace institwmissing = 0 if  institcountpercent_  == .
gen domcomplwmissing = domcompliancepercent_
replace domcomplwmissing = 0 if domcompliancepercent_ == .

**mean calculation**
 egen avgterror = rowmean(terrorismdeaths_1996 terrorismdeaths_1997 terrorismdeaths_1998 terrorismdeaths_1999 terrorismdeaths_2000 terrorismdeaths_2001 terrorismdeaths_2002 terrorismdeaths_2003 terrorismdeaths_2004 terrorismdeaths_2005 terrorismdeaths_2006 terrorismdeaths_2007 terrorismdeaths_2008 terrorismdeaths_2009) 
 egen avgaffinity = rowmean(s3un4608i_1996 s3un4608i_1997 s3un4608i_1998 s3un4608i_1999 s3un4608i_2000 s3un4608i_2001 s3un4608i_2002 s3un4608i_2003 s3un4608i_2004 s3un4608i_2005 s3un4608i_2006 s3un4608i_2007 s3un4608i_2008 s3un4608i_2009)
 egen avgtrade = rowmean(trade_1996 trade_1997 trade_1998 trade_1999 trade_2000 trade_2001 trade_2002 trade_2003 trade_2004 trade_2005 trade_2006 trade_2007 trade_2008 trade_2009) 
 egen avgaid = rowmean(usaid_1996 usaid_1997 usaid_1998 usaid_1999 usaid_2000 usaid_2001 usaid_2002 usaid_2003 usaid_2004 usaid_2005 usaid_2006 usaid_2007 usaid_2008 usaid_2009)
 egen avgcoop = rowmean(percentcoopdiff_v2_wmissing_1996 percentcoopdiff_v2_wmissing_1997 percentcoopdiff_v2_wmissing_1998 percentcoopdiff_v2_wmissing_1999 percentcoopdiff_v2_wmissing_2000 percentcoopdiff_v2_wmissing_2001 percentcoopdiff_v2_wmissing_2002 percentcoopdiff_v2_wmissing_2003 percentcoopdiff_v2_wmissing_2004 percentcoopdiff_v2_wmissing_2005 percentcoopdiff_v2_wmissing_2006 percentcoopdiff_v2_wmissing_2007 percentcoopdiff_v2_wmissing_2008 percentcoopdiff_v2_wmissing_2009)
 egen avgrelstate = rowmean(relstate5yrvary1996 relstate5yrvary1997 relstate5yrvary1998 relstate5yrvary1999 relstate5yrvary2000 relstate5yrvary2001 relstate5yrvary2002 relstate5yrvary2003 relstate5yrvary2004 relstate5yrvary2005 relstate5yrvary2006 relstate5yrvary2007 relstate5yrvary2008 relstate5yrvary2009) 
 egen avggdp = rowmean(gdp1996 gdp1997 gdp1998 gdp1999 gdp2000 gdp2001 gdp2002 gdp2003 gdp2004 gdp2005 gdp2006 gdp2007 gdp2008 gdp2009)
 